<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<table border="0" cellspacing="0" cellpadding="0">
			<tr>
				<th><img src="img/QQ截图20200210.png" ></th>
				<th style="font-size: x-large;" colspan="4">购物简易计算器</th>
			</tr>
			<tr>
				<td style="font-size: x-large;">第一个数</td>
				<td colspan="4"><input type="text" name="cal"  id="first" value=""  /></td>
			</tr>
			<tr>
				<td style="font-size: x-large;">第二个数</td>
				<td colspan="4"><input type="text" name="cal" id="second" value="" /></td>
			</tr>
			<tr>
				<td></td>
				<td><button onclick="add()">+</button></td>
				<td><button onclick="sub()">-</button></td>
				<td><button onclick="multi()">*</button></td>
				<td><button onclick="div()">/</button></td>
			</tr>
			<tr>
				<td style="font-size: x-large;">计算结果</td>
				<td colspan="4"><input type="text" name="cal"  id="result" value="" autocomplete="off" /></td>
			</tr>
			</table>
		
		<script type="text/javascript">
	;
			function add(){
				var num1 = document.getElementById("first");
				var num2 = document.getElementById("second");
				var n1 = parseInt(num1.value);
				var n2 = parseInt(num2.value);
				var res =n1 + n2;
				console.log(res);
				var n3 = document.getElementById("result");
				n3.value = res;
			}
			function sub(){
				var num1 = document.getElementById("first");
				var num2 = document.getElementById("second");
				var n1 = parseInt(num1.value);
				var n2 = parseInt(num2.value);
				var res =n1 - n2;
				console.log(res);
				var n3 = document.getElementById("result");
				n3.value = res;
			}
			function multi(){
				var num1 = document.getElementById("first").value;
				var num2 = document.getElementById("second").value;
				
				var res =parseInt(num1) * parseInt(num2);
				console.log(res);
				var n3 = document.getElementById("result");
				n3.value = res;
			}
			function div(){
				var num1 = document.getElementById("first");
				var num2 = document.getElementById("second");
				var n1 = parseInt(num1.value);
				var n2 = parseInt(num2.value);
				var res =n1 / n2;
				console.log(res);
				var n3 = document.getElementById("result");
				n3.value = res;
			}
		</script>
		
	</body>
	
</html>
